package com.vca.front.controller;

import com.vca.common.request.ComputedOrderCommonPriceRequest;
import com.vca.common.request.CreateCommonOrderRequest;
import com.vca.common.request.PreOrderCommonRequest;
import com.vca.common.response.ComputedOrderCommonPriceResponse;
import com.vca.common.response.PreOrderCommonResponse;
import com.vca.common.result.CommonResult;
import com.vca.service.service.VcaOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author chenbing
 * @date 2022/11/9   16:05
 */
@Slf4j
@RestController("VcaOrderController")
@RequestMapping("api/front/order")
@Api(tags = "订单控制器")
public class VcaOrderController {
    @Autowired
    private VcaOrderService vcaOrderService;

    /**
     * @Description:预下单
     * @Author: chenBing
     * @Date: 2022/11/21
     */
    @ApiOperation(value = "预下单")
    @PostMapping(value = "/pre/order/common")
    public CommonResult<Map<String, Object>> proOrderCommon(
            @RequestHeader(value = "language",required = false) String language,
            @RequestBody @Validated PreOrderCommonRequest request
    ) {
        return CommonResult.success(vcaOrderService.proOrderCommon(language,request));
    }

    /**
     * @Description:加载预下单
     * @Author: chenBing
     * @Date: 2022/11/22
     */
    @ApiOperation(value = "加载预下单")
    @GetMapping(value = "/load/pre/common/{preOrderNo}")
    public CommonResult<PreOrderCommonResponse> loadPreCommon(@RequestHeader(value = "language",required = false) String language,@PathVariable("preOrderNo") String preOrderNo) {
        return CommonResult.success(vcaOrderService.loadPreCommon(language,preOrderNo));
    }

    /**
     * @Description:计算订单价格
     * @Author: chenBing
     * @Date: 2022/11/22
     */
    @ApiOperation(value = "计算订单价格")
    @PostMapping(value = "/computed/common/price")
    public CommonResult<ComputedOrderCommonPriceResponse> computedCommonPrice(
            @RequestHeader(value = "language",required = false) String language,
            @Validated @RequestBody ComputedOrderCommonPriceRequest request
    ) {
        return CommonResult.success(vcaOrderService.computedCommonPrice(language,request));
    }

    /**
     * @Description:创建订单
     * @Author: chenBing
     * @Date: 2022/11/23
     */
    @ApiOperation(value = "创建订单")
    @PostMapping(value = "/create/common/order")
    public CommonResult<Map<String, Object>> createCommonOrder(
            @RequestHeader(value = "language",required = false) String language,
            @Validated @RequestBody CreateCommonOrderRequest request
    ) {
        return CommonResult.success(vcaOrderService.createCommonOrder(language,request));
    }

    /**
     * @Description:领取课程/讲座/展览/套课
     * @author:chenbing
     * @date 2022/12/1 19:17
     */
    @ApiOperation(value = "领取课程/讲座/展览/套课")
    @PostMapping(value = "/get")
    public CommonResult<String> get(
            @RequestParam(value = "orderInfoIds") List<Integer> orderInfoIds
    ) {
        if (vcaOrderService.get(orderInfoIds)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
